<template>
  <view class="start-container">
    <!-- <text>start</text> -->
  </view>
</template>

<script>
import { mapActions, mapMutations } from "vuex";
import { checkExpire } from "../../utils/auth.js";
import { SET_TOKEN } from "../../store/modules/mutation_types.js";
import { STORAGE_KEY } from "../../config/consts.js";
import Printer from "../../utils/printer";
import Vue from "vue";
export default {
  data() {
    return {};
  },
  onLoad() {
    this.init();
  },
  methods: {
    ...mapActions({
      getMainShop: "getMainShop",
      getShops: "getShops",
      getHomeData: "getHomeData"
    }),
    ...mapMutations({ ASYNC_LOCAL_TO_STORE: "ASYNC_LOCAL_TO_STORE" }),
    init() {
      this.ASYNC_LOCAL_TO_STORE();
      this.isLogin();
    },
    isLogin() {
      let isLogin = checkExpire();
      if (isLogin) {
        // global.printerUtil = new Printer(true, this.$store);
        Vue.prototype.$printerUtil = new Printer(true, this.$store);
        try {
          this.getMainShop();
          this.getShops().then(res => {
            this.getHomeData();
          }).catch(e=>{
             this.$goto("login", {}, "redirect");
          });
        } catch (error) {
          this.$goto("login", {}, "redirect");
        }
        uni.switchTab({
          url: `/pages/index/index`
        });
      } else {
        this.$goto("login", {}, "redirect");
      }
    }
  }
};
</script>

<style lang="scss">
.start-container {
  height: 100vh;
  z-index: 10000;
  background: #ffffff;
}
</style>
